const path = require("path");
const htmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require('webpack')

module.exports = {
  mode: "development",
  devtool: "cheap-module-eval-source-map",
  entry: path.join(__dirname, "src/index.js"),
  devServer: {
    contentBase: './dist',
    open: true,
    hot: true,
    hotOnly: true,
    historyApiFallback: true,
    proxy: {
      '/react/api': {
        target: 'http://www.dell-lee.com',
        secure: false,
        pathRewrite: {
          'header.json': 'demo.json'
        },
        changeOrigin: true,
        headers: {
          host: 'www.dell-lee.com'
        }
      }
    }
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "babel-loader",
      }
    ]
  },
  output: {
    publicPath: '/',
    filename: "[name]-[hash:8].js",
    path: path.join(__dirname, "dist")
  },
  plugins: [
    new htmlWebpackPlugin({ template: "./src/index.html" }),
    new webpack.HotModuleReplacementPlugin()
  ]
};
